/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmAsignacion.java
 *
 * Created on 7/06/2012, 11:01:28 AM
 */

package presentacion;

import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;
import negocios.Cliente;
import negocios.Habitacion;

/**
 *
 * @author userlab26
 */
public class frmAsignacion extends javax.swing.JDialog {
    private Cliente cliCliente=null;

    /** Creates new form frmAsignacion */
    public frmAsignacion(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        lblEtiquetaNumero = new javax.swing.JLabel();
        txtNumeroH = new javax.swing.JTextField();
        lblEtiquetaFechaI = new javax.swing.JLabel();
        lblEtiquetaHora = new javax.swing.JLabel();
        btnBuscar = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        lblEtiquetaNombre = new javax.swing.JLabel();
        btnAceptar = new javax.swing.JButton();
        cmbDia = new javax.swing.JComboBox();
        cmbMes = new javax.swing.JComboBox();
        cmbAño = new javax.swing.JComboBox();
        cmbHora = new javax.swing.JComboBox();
        cmbMinuto = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        lblNombre = new javax.swing.JLabel();
        txtCampoBusqueda = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(presentacion.Laboratorio3App.class).getContext().getResourceMap(frmAsignacion.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        lblEtiquetaNumero.setText(resourceMap.getString("lblEtiquetaNumero.text")); // NOI18N
        lblEtiquetaNumero.setName("lblEtiquetaNumero"); // NOI18N

        txtNumeroH.setText(resourceMap.getString("txtNHuespedes.text")); // NOI18N
        txtNumeroH.setName("txtNHuespedes"); // NOI18N

        lblEtiquetaFechaI.setText(resourceMap.getString("lblEtiquetaFechaI.text")); // NOI18N
        lblEtiquetaFechaI.setName("lblEtiquetaFechaI"); // NOI18N

        lblEtiquetaHora.setText(resourceMap.getString("lblEtiquetaHora.text")); // NOI18N
        lblEtiquetaHora.setName("lblEtiquetaHora"); // NOI18N

        btnBuscar.setText(resourceMap.getString("btnBuscar.text")); // NOI18N
        btnBuscar.setName("btnBuscar"); // NOI18N
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        btnCancel.setText(resourceMap.getString("btnCancelar.text")); // NOI18N
        btnCancel.setName("btnCancelar"); // NOI18N
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        lblEtiquetaNombre.setText(resourceMap.getString("lblEtiquetaNombre.text")); // NOI18N
        lblEtiquetaNombre.setName("lblEtiquetaNombre"); // NOI18N

        btnAceptar.setText(resourceMap.getString("btnAceptar.text")); // NOI18N
        btnAceptar.setName("btnAceptar"); // NOI18N
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        cmbDia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        cmbDia.setName("cmbDia"); // NOI18N

        cmbMes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
        cmbMes.setName("cmbMes"); // NOI18N

        cmbAño.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2011", "2012", "2013" }));
        cmbAño.setName("cmbAno"); // NOI18N

        cmbHora.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24" }));
        cmbHora.setName("cmbHora"); // NOI18N

        cmbMinuto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60" }));
        cmbMinuto.setName("cmbMinuto"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setEnabled(false);
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setEnabled(false);
        jLabel10.setName("jLabel10"); // NOI18N

        lblNombre.setText(resourceMap.getString("lblNombre.text")); // NOI18N
        lblNombre.setName("lblNombre"); // NOI18N

        txtCampoBusqueda.setText(resourceMap.getString("txtCampoBusqueda.text")); // NOI18N
        txtCampoBusqueda.setName("txtCampoBusqueda"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(lblEtiquetaNombre)
                            .addGap(82, 82, 82))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(75, 75, 75)))
                    .addComponent(lblEtiquetaNumero)
                    .addComponent(lblEtiquetaFechaI)
                    .addComponent(lblEtiquetaHora))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnCancel)
                        .addGap(17, 17, 17)
                        .addComponent(btnAceptar))
                    .addComponent(lblNombre)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmbHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(cmbMinuto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmbDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(cmbMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmbAño, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtCampoBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuscar))
                    .addComponent(txtNumeroH, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnBuscar)
                            .addComponent(txtCampoBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(lblNombre)
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(1, 1, 1)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbAño, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10))
                        .addGap(3, 3, 3)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbMinuto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblEtiquetaHora))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnCancel)
                            .addComponent(btnAceptar)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(lblEtiquetaNombre))
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblEtiquetaNumero)
                            .addComponent(txtNumeroH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(24, 24, 24)
                        .addComponent(lblEtiquetaFechaI)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here:
        int id=Integer.parseInt(txtCampoBusqueda.toString());
        cliCliente=(Cliente) ControlHabitacionesView.lstclientes.get(id);
        jLabel1.setText(cliCliente.getNombre());
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        // TODO add your handling code here:
        Habitacion habDesocupada=null;
        Habitacion habDesocupada2=null;
        int intAño,intMes,intDia,intHora,intMinuto;
        intAño=Integer.parseInt(cmbAño.getSelectedItem().toString());
        intMes=Integer.parseInt(cmbMes.getSelectedItem().toString());
        intDia=Integer.parseInt(cmbDia.getSelectedItem().toString());
        intHora=Integer.parseInt(cmbHora.getSelectedItem().toString());
        intMinuto=Integer.parseInt(cmbMinuto.getSelectedItem().toString());


        GregorianCalendar calFechaIngreso=new GregorianCalendar(intAño,intMes,intDia,intHora,intMinuto,0);
        Habitacion habIterador=null;
        for (int i=0;i<ControlHabitacionesView.lsthabitaciones.size();i++)
        {
            habIterador=(Habitacion) ControlHabitacionesView.lsthabitaciones.get(i);
            if (!habIterador.fnbAsignada()){
                if (habIterador.getPersonas()==Integer.parseInt(txtNumeroH.getText())){
                    habDesocupada=habIterador;
                    break;
                }
                else if (habIterador.getPersonas()>=Integer.parseInt(txtNumeroH.getText()))
                    habDesocupada2=habIterador;
            }
        }
        if (habDesocupada!=null)
        {
            habDesocupada.fnvAsignarHabitacion(cliCliente, calFechaIngreso);
            JOptionPane.showMessageDialog(this, "Se ha asignado en la habitación No. "+habDesocupada.getIdHabitacion());
        }
        else{
            if (habDesocupada2!=null){
                habDesocupada2.fnvAsignarHabitacion(cliCliente, calFechaIngreso);
                JOptionPane.showMessageDialog(this, "Se ha asignado en la habitación No. "+habDesocupada2.getIdHabitacion());
            }
            else
                JOptionPane.showMessageDialog(this,"No se encontró habitación libre para asignar");
        }
    }//GEN-LAST:event_btnAceptarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                frmAsignacion dialog = new frmAsignacion(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancel;
    private javax.swing.JComboBox cmbAño;
    private javax.swing.JComboBox cmbDia;
    private javax.swing.JComboBox cmbHora;
    private javax.swing.JComboBox cmbMes;
    private javax.swing.JComboBox cmbMinuto;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel lblEtiquetaFechaI;
    private javax.swing.JLabel lblEtiquetaHora;
    private javax.swing.JLabel lblEtiquetaNombre;
    private javax.swing.JLabel lblEtiquetaNumero;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JTextField txtCampoBusqueda;
    private javax.swing.JTextField txtNumeroH;
    // End of variables declaration//GEN-END:variables

}
